package com.learn.databinding.twowaydatabinding

import android.view.View
import androidx.databinding.InverseMethod
import java.text.SimpleDateFormat
import java.util.Date

object Converter {
    /**
     * 通过[@InverseMethod]注解指定逆转换
     */
    @InverseMethod("stringToDate")
    @JvmStatic
    fun dateToString(
        view: View,
        oldValue: Long,
        value: Long
    ): String {
        // converts long to String
        val format = SimpleDateFormat("yyyy-MM-dd").also {
            it.isLenient = false
        }
        return format.format(Date(value))
    }

    @JvmStatic
    fun stringToDate(
        view: View,
        oldValue: String,
        value: String
    ): Long {
        // converts String to Long
        //TODO converts String to Long
        return 0
    }
}